<div class="layui-card">
    <div class="layui-card-body">
        <table class="layui-table" id="adopt-table" lay-filter="adopt-table"></table>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="task-reply-table-bar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="adopt">采纳</a>
</script>

<script>
    layui.use(['form', 'table', 'util', 'config', 'admin'], function () {
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var layer = layui.layer;
        var util = layui.util;
        var admin = layui.admin;

        let task = admin.getTempData('t_task');
        // 渲染表格
        table.render({
            elem: '#adopt-table',
            // url: config.base_server + 'user_query.json',
            url: config.base_server + 'api-task/task/findMyPublishTaskAdopt',
            method: 'GET',
            where: {
                access_token: config.getToken().access_token,
                taskid: task.taskid
            },
            page: true,
            cols: [[
                {type: 'numbers'},
                {field: 'retype', sort: true, title: '回复方式'},
                {field: 'conten', sort: true, title: '回复内容'},
                {field: 'retime', sort: true, title: '回复时间'},
                {
                    templet: function (d) {
                        if (d.status == 1) {
                            return '<div id="adopt" class="layui-btn layui-btn-primary layui-btn-xs" lay-event="adopt">采纳</div>';
                        } else {
                            return '已采纳';
                        }
                    }, title: '操作'
                },
                // {align: 'center', toolbar: '#task-reply-table-bar', title: '操作', width: 120}
            ]]
        })

        // 工具条点击事件
        table.on('tool(adopt-table)', function (obj) {
            let data = obj.data;
            let layEvent = obj.event;

            if (layEvent === 'adopt') { // 采纳
                console.log(data)
                let replid = data.replid;
                let userid = data.userid;
                let taskid = data.taskid;
                let reply = {
                    replid: replid,
                    userid: userid,
                    taskid: taskid
                }
                admin.req('api-task/task/adoptReply', JSON.stringify(reply), function (data) {
                    // console.log(data);
                    layer.closeAll('loading');
                    if (data.code == 0) {
                        layer.msg(data.msg, {icon: 1, time: 500});
                        admin.finishPopupCenter();
                    } else {
                        layer.msg(data.msg, {icon: 2, time: 500});
                    }
                }, 'POST')
            }
        });

    });
</script>